/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Servlets;

import BancoDados.Solicitacao;
import Sistema.GerenciadorServlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created on : Jun 8, 2011, 7:58:42 PM
 * @author diogo
 */
@WebServlet(name="ServletSolicitacoes", urlPatterns={"/ServletSolicitacoes"})
public class ServletSolicitacoes extends HttpServlet {
   // <editor-fold defaultstate="collapsed" desc="netbeans default template">
////    /**
////     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
////     * @param request servlet request
////     * @param response servlet response
////     * @throws ServletException if a servlet-specific error occurs
////     * @throws IOException if an I/O error occurs
////     */
////    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
////    throws ServletException, IOException {
////        response.setContentType("text/html;charset=UTF-8");
////        PrintWriter out = response.getWriter();
////        try {
////            /* TODO output your page here
////            out.println("<html>");
////            out.println("<head>");
////            out.println("<title>Servlet CadastroSolicitacoes</title>");
////            out.println("</head>");
////            out.println("<body>");
////            out.println("<h1>Servlet CadastroSolicitacoes at " + request.getContextPath () + "</h1>");
////            out.println("</body>");
////            out.println("</html>");
////            */
////        } finally {
////            out.close();
////        }
////    }
	// </editor-fold>

    /**
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        StringBuffer output = new StringBuffer("");


        response.getWriter().print(output);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        GerenciadorServlet.Codificar(request, response);
		StringBuffer output = new StringBuffer("");
		String tipo = request.getParameter("tipo");
		if (tipo.equals("inserir")) {
			boolean resultado;
	//		request.setAttribute("DataSolicitacao", new Date());
	//		request.setAttribute("DataAtendimento", null);
			resultado = Solicitacao.Inserir(request);
			output.append(resultado);
		} else if (tipo.equals("atualizarNivel")){
			int CodSolicitacao = 0;
			int CodProfissional = 0;
			int novoNivel = 0;
			boolean resultado = false;
			try {
				CodSolicitacao = Integer.parseInt(request.getParameter("codSolicitacao"));
				CodProfissional = Integer.parseInt(request.getParameter("codProfissional"));
				novoNivel = Integer.parseInt(request.getParameter("novoNivel"));
			} catch (Exception e) {
			}
			
			resultado = Solicitacao.AtualizaNivel(CodSolicitacao, CodProfissional, novoNivel);
			//output.append(String.format("peguei : cod sol: %s, prof %s, nivel %s",sCodSolicitacao, sCodProfissional, sNovoNivel ));
			output.append(resultado);
		}

        response.getWriter().print(output);
    }

    // <editor-fold defaultstate="collapsed" desc="netbeans default template">
    /**
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
////    @Override
////    public String getServletInfo() {
////        return "Short description";
////    }
    // </editor-fold>
}
